window.addEventListener('keydown',
    function (event) {
        // event 包含键值的ASCII码
        let keyCode = event.keyCode;//按键事件的数据
        // console.log(keyCode);
        let audioEle =
            document.querySelector(`audio[data-key="${keyCode}"]`);
        // console.log(audioEle);
        if (!audioEle) return;
        audioEle.play();

        let keyEle =
            document.querySelector(`.key[data-key="${keyCode}"]`);
        if (!keyEle) return;
        keyEle.classList.add('playing');
        // 定时器 
        // this.setTimeout(function () {
        //     keyEle.classList.remove('playing');
        // }, 300)
    })

const keys = document.querySelectorAll('.key');
for (let key of keys) {
    // event 只能一个个加 不能集体加
    key.addEventListener('transitionend', function (event) {
        event.target.classList.remove('playing');
    });
}